home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
OS
/
ZPointer.h
< prev
next >
Wrap
Text File
|
1997-06-18
|
2KB
|
87 lines
/*
* File: ZPointer.h
* Summary: A class to encapsulate non-relocatable memory.
* Written by: Jesse Jones
*
* Abstract: TPointer uses reference counting so that when an
* TPointer is copied the old and new objects point to
* the same block of memory. This means that TPointer
* objects can be treated just like regular pointer's. In
* particular, they can be passed by value without allocating
* a new chunk of memory.
*
* Usage: There are three ways to allocate memory in Raven: operator new,
* THandle, and TPointer. The new operator should be used to
* allocate small amounts of memory that won't change size.
* TMemHandle should be used for large chunks of memory. TPointer
* should be used for large chunks of memory that cannot move.
*
* Copyright ゥ 1996 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 1/14/96 JDJ Created.
*/
#pragma once
#include <ZConstants.h>
#include <ZTypes.h>
//-----------------------------------
// Forward References
//
class ZPointerRef;
// ===================================================================================
// class TPointer
// ===================================================================================
class TPointer {
//-----------------------------------
// Initialization/Destruction
//
public:
~TPointer();
explicit TPointer(ulong bytes = 0, bool zeroBytes = kDontZeroBytes);
TPointer(Ptr takePtr);
TPointer(const TPointer& rhs);
TPointer& operator=(const TPointer& rhs);
//-----------------------------------
// New API
//
public:
const Byte* GetPtr() const;
Byte* GetPtr();
ulong GetSize() const;
void SetSize(ulong bytes, bool zeroBytes = kDontZeroBytes);
// Note that this may invalidate references to the pointer!
void Detach();
// If the letter is being shared this will create a new letter
// referenced only by 'this'.
bool operator==(const TPointer& rhs) const;
bool operator!=(const TPointer& rhs) const {return !this->operator==(rhs);}
//-----------------------------------
// Member data
//
private:
ZPointerRef* mPointerRef;
};